# -*- coding: utf-8 -*-
# Description: 文件夹或路径操作辅助方法
import os

if os.name == 'nt':
    FolderExistsError = (WindowsError, OSError)
    FolderExistsCode = (183, 17)
elif os.name == 'posix':
    FolderExistsError = (OSError,)
    FolderExistsCode = (17,)
    
def ensure_dir_exists(dirPath):
    if not os.path.exists(dirPath):
        try:
            os.makedirs(dirPath)
        except OSError, e:
            if not e.args[0] in (183, 17):
                raise
            
def get_files(dir):
    """获取一个文件夹下的所有文件"""
    files_list = []
    for root, dirs, files in os.walk(dir, topdown=False):
        del dirs
        for each_file in files:
            file_path = os.path.join(root, each_file)
            if os.path.isfile(file_path):
                files_list.append(file_path)
    return files_list

def get_dirs(dir):
    files_list = []
    names_list = os.listdir(dir)
    for name in names_list:
        file_path = os.path.join(dir, name)
        files_list.append(file_path)
    return files_list

if __name__ == '__main__':
    print get_files(r'D:\aa')
    print get_dirs(r'D:\aa')
    
